package com.ruoyi.security.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.security.domain.SecurityDuty;
import com.ruoyi.security.service.ISecurityDutyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 保安值班Controller
 *
 * @author cjie
 * @date 2022-04-27
 */
@Api(tags = " 保安值班")
@RestController
@RequestMapping("/securityDuty")
public class SecurityDutyController extends BaseController {
    @Autowired
    private ISecurityDutyService securityDutyService;

    /**
     * 查询保安值班列表
     */
    @ApiOperation(value="查询保安值班列表", notes="查询保安值班列表")
    @PreAuthorize(hasPermi = "security:securityDuty:list")
    @GetMapping("/list")
    public TableDataInfo list(SecurityDuty securityDuty) {
        startPage();
        List<SecurityDuty> list = securityDutyService.selectSecurityDutyList(securityDuty);
        return getDataTable(list);
    }

    /**
     * 导出保安值班列表
     */
    @ApiOperation(value="导出保安值班列表", notes="导出保安值班列表")
    @PreAuthorize(hasPermi = "security:securityDuty:export")
    @Log(title = "保安值班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SecurityDuty securityDuty) throws IOException {
        List<SecurityDuty> list = securityDutyService.selectSecurityDutyList(securityDuty);
        ExcelUtil<SecurityDuty> util = new ExcelUtil<SecurityDuty>(SecurityDuty.class);
        util.exportExcel(response, list, "保安值班数据");
    }
    /**
     * 获取保安值班详细信息
     */
    @ApiOperation(value="获取保安值班详细信息", notes="获取保安值班详细信息")
    @PreAuthorize(hasPermi = "security:securityDuty:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(securityDutyService.selectSecurityDutyById(id));
    }

    /**
     * 新增保安值班
     */
    @ApiOperation(value="新增保安值班", notes="新增保安值班")
    @PreAuthorize(hasPermi = "security:securityDuty:add")
    @Log(title = "保安值班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SecurityDuty securityDuty) {
        return toAjax(securityDutyService.insertSecurityDuty(securityDuty));
    }

    /**
     * 修改保安值班
     */
    @ApiOperation(value="修改保安值班", notes="修改保安值班")
    @PreAuthorize(hasPermi = "security:securityDuty:edit")
    @Log(title = "保安值班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SecurityDuty securityDuty) {
        return toAjax(securityDutyService.updateSecurityDuty(securityDuty));
    }

    /**
     * 删除保安值班
     */
    @ApiOperation(value="删除保安值班", notes="删除保安值班")
    @ApiImplicitParam(name = "ids", value = "保安值班ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "security:securityDuty:remove")
    @Log(title = "保安值班", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(securityDutyService.deleteSecurityDutyByIds(ids));
    }
}
